package main

func main() {

}

type ListNode struct {
	Val  int
	Next *ListNode
}

// 删除倒数第n个结点
func removeNthFromEnd(head *ListNode, n int) *ListNode {
	dummyNode := &ListNode{}
	dummyNode.Next = head

	pre, cur := dummyNode, dummyNode
	for i := 0; i < n; i++ {
		cur = cur.Next
	}

	for cur.Next != nil {
		pre = pre.Next
		cur = cur.Next
	}

	pre.Next = pre.Next.Next
	return dummyNode.Next
}
